package aspectJ.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import annotationI.SaferParam;

@Aspect
public class MyAspect {
	@Around("execution (@annotationI.SaferParam * *(..)) "+
			"&& within(aspectJ..*) "+
			"&& @annotation(safer)")
	public Object traceAround(ProceedingJoinPoint thisJoinPoint, SaferParam safer){
		System.out.println("Safer Param PointCut");
		Object [] argArray = thisJoinPoint.getArgs();
		for(int i : safer.param()){		
			if(argArray.length <= i + 1) break;
			if(argArray[i - 1] == null){
				System.err.println("Param " + i + " is null");
				return null;
			}
		}
		return thisJoinPoint.proceed();
	}
}
